<?php
declare (strict_types=1);

namespace app\index\controller;

use app\common\tool\Result;
use think\facade\View;
use think\Response;
use app\common\model\Remit as RemitModel;
use think\exception\ValidateException;

class Remit extends Base
{
    public function index(): string
    {
        return View::fetch();
    }

    public function record(): string
    {
        return View::fetch();
    }

    public function getList(): Response
    {
        return Result::fastReturn(RemitModel::getPageList(['uid' => $this->user->id],
            'id,account,amount,pay_way,status,reject_msg,create_time',
            $this->getPage(), $this->getLimit(), false, [], [], [], [], [], '', ['status_name']));
    }

    public function save(): Response
    {
        $param = $this->request->post();
        try {
            $this->validate($param, 'Remit');
        } catch (ValidateException $e) {
            return Result::fail($e->getError());
        }

        return Result::fastReturn(RemitModel::add($param, $this->user, $this->system));
    }
}